<script>
import Vue from "vue";
import { checkAppUpdate } from "@/tools/utils.js";
export default {
	methods: {
		/**
		 * 存储设备信息 参考colorUI
		 * @param {Object}
		 */
		initSize(e) {
			const systemInfo = e;
			let navigationBarHeight;
			let custom = {};
			// #ifndef MP
			custom = {
				height: 36,
				width: 88
			};
			navigationBarHeight = 44;
			// #endif
			// #ifdef MP-WEIXIN
			custom = wx.getMenuButtonBoundingClientRect();
			navigationBarHeight = custom.bottom + custom.top - e.statusBarHeight * 2;
			// #endif
			systemInfo.custom = custom;
			systemInfo.navigationBarHeight = navigationBarHeight;
			systemInfo.development = process.env.NODE_ENV == "development";
			this.$u.vuex("vx_systemInfo", systemInfo);
		},
		/**
		 * 初始化push相关
		 */
		async initPush() {
			plus.push.addEventListener("receive", (msg) => {
				// 收到推送信息
				console.log("receive push message", msg);
				let data = JSON.parse(msg.payload);
				console.log("receive push message", data);
			});
			plus.push.addEventListener("click", (msg) => {
				// 点击推送信息
				console.log("click push message", msg);
			});
			plus.push.getClientInfoAsync(
				(info) => {
					console.log("push.getClientInfoAsync.success", info);
					this.$store.commit("updatePushInfo", info);
					this.$store.dispatch("updatePushClient");
				},
				(err) => {
					console.log("push.getClientInfoAsync.error", err);
				}
			);
		}
	},
	onLaunch: function () {
		console.log("App Launch");
		// #ifdef APP-PLUS
		// 如果用户接收了隐私政策和用户协议
		if (plus.runtime.isAgreePrivacy()) {
			// #endif
			const info = uni.getSystemInfoSync();
			this.initSize(info);
			// #ifdef APP-PLUS
		}
		// #endif
		//#ifdef APP-PLUS
		//检查应用更新，每日一次
		checkAppUpdate();
		//初始化推送
		this.initPush();
		//#endif
	},
	onShow: function () {
		console.log("App Show");
	},
	onHide: function () {
		console.log("App Hide");
	}
};
</script>

<style lang="scss">
@import "./static/css/iconfont.css";
/*每个页面公共css */
@import "uview-ui/index.scss";
@import "common/css/app.scss";

image {
	vertical-align: middle;
	width: 100%;
	height: 100%;
}
view {
}

.flex {
	display: flex;
	align-items: center;
}
.flex_bw {
	display: flex;
	align-items: center;
	justify-content: space-between;
}
.flex_center {
	display: flex;
	align-items: center;
	justify-content: center;
}
</style>
